home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 55 / XENIATGM55.iso / Goodies / OGL 16bit / ogl16bit.c next >
C/C++ Source or Header  |  1998-11-03  |  4KB  |  152 lines

  1. /*
  2. ==============================================================================
  3. Title: "16-bit Texture Enabler For 3Dfx's Win32 Quake OpenGL Miniport"
  4. (c) 1998 by Matthias "Maddes" Buecher
  5.  
  6. Authors:
  7. Matthias "Maddes" Buecher <maddes@bigfoot.com>
  8.  
  9. Important:
  10. It should compile under Win32 with no errors, some warnings may still occur.
  11.  
  12. DISCLAIMER WARNING:
  13. WE DO NOT ACCEPT RESPONSIBILITY FOR ANY EFFECTS, POSITIVE OR NEGATIVE,
  14. THAT THIS CODE MAY CAUSE TOWARDS YOUR COMPUTER.
  15. WE DO NOT SUPPORT MODIFICATIONS OF THIS CODE, USE ONLY AT YOUR OWN RISK.
  16. THIS PATCH HAS NOT BEEN ENDORSED BY THE ID SOFTWARE CORPORATION.
  17. THIS PROGRAM IS FREE OF CHARGE. IF YOU HAVE RECEIVED THIS PROGRAM THROUGH
  18. PAYMENT, PLEASE CONTACT US.
  19. OTHERWISE ENJOY THE PROGRAM. THANK YOU.
  20. ==============================================================================
  21. */
  22.  
  23. /* Compatible headers */
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <errno.h>
  28.  
  29. #define BUFLEN 10240    /* 10KB */
  30. #define SEARCHLEN 29    /* 10KB */
  31.  
  32. unsigned char orgname[SEARCHLEN+1] = "GL_EXT_shared_texture_palette";
  33. unsigned char newname[SEARCHLEN+1] = "DISABLEshared_texture_palette";
  34.  
  35. long compare(unsigned char *m1, unsigned char *m2, long n, long l)
  36. {
  37.     long i, j;
  38.  
  39.     for (i=0; i<=(n-l); i++)
  40.     {
  41.         if (m1[i] == m2[0])
  42.         {
  43.             for (j=0; j<l; j++)
  44.             {
  45.                 if (m1[i+j] != m2[j]) break;
  46.             }
  47.             if (j==l) break;
  48.         }
  49.     }
  50.     if (i<=(n-l)) return i;
  51.  
  52.     return -1;
  53. }
  54.  
  55. void process_file(char *path)
  56. {
  57.     FILE *data;
  58.  
  59.     unsigned char buffer[BUFLEN];
  60.     long foffset, bytes, found;
  61.     int flag_orgname, flag_newname;
  62.  
  63.     printf("*** Processing \"%s\"\n", path);
  64.  
  65.     /* open data file */
  66.     data = fopen(path, "r+b");
  67.     if (!data)
  68.     {
  69.         if (errno == EACCES)
  70.             printf("Warning: can not access file - write protected or a directory?\n");
  71.         else
  72.             printf("Warning: file not found\n");
  73.     }
  74.     else
  75.     {
  76.         foffset = 0;
  77.         flag_orgname = 0;
  78.         flag_newname = 0;
  79.  
  80.         while (bytes = fread(buffer, 1, BUFLEN, data))
  81.         {
  82.             if (!flag_newname)
  83.             {
  84.                 found = compare(buffer, orgname, bytes, SEARCHLEN);
  85.                 if ( found >= 0 )
  86.                 {
  87.                     flag_orgname = 1;
  88.                     printf("Found \"%s\" at offset %li\n", orgname, foffset+found);
  89.                     if ( fseek(data, foffset+found, SEEK_SET) != 0 || ftell(data) != foffset+found )
  90.                     {
  91.                         printf("Error: can not position into file\n");
  92.                         break;
  93.                     }
  94.                     if ( fwrite(newname, SEARCHLEN, 1, data) != 1 )
  95.                     {
  96.                         printf("Error: can not write into file\n");
  97.                         break;
  98.                     }
  99.                     fseek(data, 0, SEEK_CUR);    /* needed to switch from writing to reading */
  100.                 }
  101.             }
  102.             if (!flag_orgname)
  103.             {
  104.                 found = compare(buffer, newname, bytes, SEARCHLEN);
  105.                 if ( found >= 0 )
  106.                 {
  107.                     flag_newname = 1;
  108.                     printf("Found \"%s\" at offset %li\n", newname, foffset+found);
  109.                     if ( fseek(data, foffset+found, SEEK_SET) != 0 || ftell(data) != foffset+found )
  110.                     {
  111.                         printf("Error: can not position into file\n");
  112.                         break;
  113.                     }
  114.                     if ( fwrite(orgname, SEARCHLEN, 1, data) != 1 )
  115.                     {
  116.                         printf("Error: can not write into file\n");
  117.                         break;
  118.                     }
  119.                     fseek(data, 0, SEEK_CUR);    /* needed to switch from writing to reading */
  120.                 }
  121.             }
  122.  
  123.             if (bytes < BUFLEN) break;
  124.             foffset = ftell(data);
  125.         }
  126.         fclose(data);
  127.     }
  128. }
  129.  
  130. int main(int argc, char *argv[])
  131. {
  132.     /* display program header lines */
  133.     printf("16-bit Texture Enabler For 3Dfx's Win32 Quake OpenGL Miniport\n");
  134.     printf("(c) 1998 by Matthias \"Maddes\" Buecher\n\n");
  135.  
  136.     if (argc != 2)
  137.     {
  138.         /* syntax */
  139.         printf("Usage: OGL16BIT <opengl32.dll>\n");
  140.         /* contact */
  141.         printf("\nHow to contact the author:\n");
  142.         printf("Matthias \"Maddes\" Buecher <maddes@bigfoot.com>\n");
  143.     }
  144.     else
  145.     {
  146.         process_file(argv[1]);
  147.     }
  148.  
  149.     return 0;
  150. }
  151.  
  152.